<?php
/**
* Description:用户设置中心
* @Author: Tudo<997470395@qq.com>
* @Created: 2015-4-10 上午9:40:57
*/
namespace Home\Controller;
class SetController extends SpaceController
{
	public function index(){
	    $this->assign("place", D('Region')->getInitPlace());
        $this->assign("base_info",D('User')->baseInfo($this->userInfo['id']));
	    if($this->userInfo['user_type']==0){
	        $this->display("index_p");
	    }else{
	        $this->display("index");
	    }
		
	}
	
	//设置基本信息
	public function base(){
		M('User')->where(array('id'=>$this->userInfo['id']))->save(array('mobile'=>I('post.mobile','',"trim"),"nick_name"=>I('post.nick_name','','trim')));
		
		$data['nick_name'] = I('post.nick_name','','trim');
		$data['province']  = I('post.province','','trim');
		$data['city'] = I('post.city');
		$data['country']  = I('post.country');
		$data['address'] =I('post.address','','trim');
		$data['qq'] = I('post.qq');
		$data['introduce'] = I('post.introduce');

		M('UserInfo')->where(array('uid'=>$this->userInfo['id']))->save($data);
		$this->success("基本信息更新成功",U('Set/index'));
	}
	
	//认证信息
	public function ideinfo(){
		
	}
	
	//密码修改
	public function password(){
	   
		$oldPwd = I('post.o_pwd','','trim');
		$newPwd = I('post.new_pwd','','trim');
		$newPwd2 = I('post.new_pwd2','','trim');
	
		if($newPwd!=$newPwd2){
		    $this->error("两次输入的密码不一样！");
		}
		
		$bool =D('User')->isTruePassword($oldPwd,$this->userInfo['id']);
		if($bool==false) $this->error("原密码输入不正确！");
		$bool = D('User')->updatePassword($this->userInfo['id'],$newPwd);
		if($bool==false) $this->error("密码更新失败");
		$this->success("密码更新成功！"); 
	}
}